﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightTcpClient
{
    public partial class EnterNamePage : UserControl
    {
        public event Action<string> NameChanged;

        public EnterNamePage()
        {
            InitializeComponent();
        }

        public void Attach(UserControl u)
        {
            u.KeyDown += new KeyEventHandler(u_KeyDown);
        }

        void u_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (this.Visibility == Visibility.Visible)
                {
                    enterButton_Click(this, new RoutedEventArgs());
                }
            }
        }

        private void enterButton_Click(object sender, RoutedEventArgs e)
        {
            if (NameChanged != null) NameChanged(textBox1.Text);
            this.IsEnabled = false;
            this.Visibility = Visibility.Collapsed;
        }
    }
}
